package org.example.resourceplatform.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDateTime;

@Entity
@Table(name = "doc_collect",
        uniqueConstraints = @UniqueConstraint(name = "uk_collect_user_doc", columnNames = {"user_id", "doc_id"}),
        indexes = {
                @Index(name = "idx_collect_user", columnList = "user_id"),
                @Index(name = "idx_collect_doc", columnList = "doc_id")
        })
@Getter
@Setter
@NoArgsConstructor
public class DocCollect {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "collect_id")
    private Integer collectId;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "doc_id", nullable = false)
    private Document document;

    @CreationTimestamp
    @Column(name = "collect_time", nullable = false, updatable = false)
    private LocalDateTime collectTime;

    public DocCollect(User user, Document document) {
        this.user = user;
        this.document = document;
    }
}